<template>
    <div class="body-bj password-box" ref="homePage">
        <div class="header"></div>
		<div class="centent">
			<div class="login-box">
                <div class="login-ww">
                    <div class="login-input">
                        <span class="passwoed-title">欢迎注册</span>
                        <el-form :model="formLabelAlign">
                            <el-form-item class="yzm">
                                <el-input v-model="formLabelAlign.username" type="text"></el-input>
                                <span class="fsYzm">6-20个字符(中文,字母,数字,下划线)</span>
                            </el-form-item>
                            <el-form-item class="yzm">
                                <el-input v-model="formLabelAlign.password" type="password"></el-input>
                                <span class="fsYzm">6-20个字符(字母,数字,特殊符号)区分大小写</span>
                            </el-form-item>
                            <el-form-item class="yzm">
                                <el-input v-model="pwd" type="password" @input="watchPwd"></el-input>
                                <span class="fsYzm" :style="{color:colorRed}">{{pwdTs}}</span>
                            </el-form-item>
                        </el-form>
                        <span class="password-button" @click="zhuce()">注册</span>
                    </div>
                </div>
			</div>
		</div>
        <ul class="falv">
            <router-link tag="li" :to="{name:'theLaw',query:{name:'法律声明'}}"><span>法律声明</span></router-link>
            <router-link tag="li" :to="{name:'theLaw',query:{name:'隐私政策声明'}}"><span>隐私政策声明</span></router-link>
            <router-link tag="li" :to="{name:'theLaw',query:{name:'举报不良信息'}}"><span>举报不良信息</span></router-link>
            <router-link tag="li" :to="{name:'theLaw',query:{name:'可接受的使用政策'}}"><span>可接受的使用政策</span></router-link>
        </ul>
    </div>
</template>
<script>
import apiHttp from '../../api/index.js'
export default {
    data(){
        return{
            clientHeight:'',
            formLabelAlign: {
                username: '',
                password: '',
            },
            pwd:'',
            pwdTs:'再次输入您的密码',
            colorRed:''
        }
    },
    mounted(){
        this.clientHeight = `${document.documentElement.clientHeight}`
        window.onresize = function temp(){
            this.clientHeight = `${document.documentElement.clientHeight}`
        }
    },
    watch:{
        clientHeight(){
            this.changeFixed(this.clientHeight)
        }
    },
    methods:{
        changeFixed(clientHeight){
            let w = clientHeight
            this.$refs.homePage.style.height = `${w}px`
        },
        // 监听密码二次确认
        watchPwd(){
            if(this.pwd.length > 0){
                if(this.pwd != this.formLabelAlign.password){
                    this.pwdTs = '两次输入的密码不一致'
                    this.colorRed = 'red'
                }else{
                    this.pwdTs = '正确'
                    this.colorRed = 'green'
                }
            }else if(this.pwd.length == 0){
                this.pwdTs = '再次输入您的密码'
                this.colorRed = ''
            }
        },
        zhuce(){
            if(this.formLabelAlign.username && this.formLabelAlign.password){
                apiHttp.apiIndex.regist(this.formLabelAlign).then(resp=>{
                    if(resp.code == 0){
                        this.$message({
                            message: '注册成功',
                            type: 'success'
                        })
                        this.$router.push({
                            name:'login'
                        })
                    }else{
                        this.$message.error(resp.message)
                    }
                })
            }else{
                this.$message({
                    message: '请检查账号或者密码',
                    type: 'warning'
                })
            }
        }
    }
}
</script>

<style scoped>
.body-bj{
    width: 100%;
    height: 100%;
    background: url(../../../static/img/content.jpg) no-repeat center;
    background-size: cover;
    overflow: hidden;
    position: relative;
}
.header{
    background: url(../../../static/img/header.jpg) no-repeat center #5d2805;
    width: 100%;
    height: 119px;
}
.centent{
    width: 100%;
    height: 100%;
}
.login-box{
    width: 550px;
    min-height: 365px;
    position: fixed;
    top:50%;
    left: 50%;
    margin-left: -255px;
    margin-top: -250px;
}
.login-ww{
    width: 550px;
    min-height: 345px;
    background-color: #f7f5ec;
    overflow: hidden;
}
.login-input{
    padding: 20px;
    width: 470px;
    min-height: 290px;
    background-color: #fff;
    margin: 20px auto;
    box-shadow: 0 0 10px #e2dacd;
}
.biaoti{
    width: 100%;
    font-size: 34px;
    font-weight: bold;
    text-align: center;
    padding-top: 30px;
    display: block;
}
.passwoed-title{
    font-size: 20px;
    display: block;
    height: 50px;
    line-height: 50px;
    color: #5d2805;
    font-weight: bold;
    width: 75%;
}
</style>
<style lang="less">
.password-box{
    .el-form-item{
        height: 40px;
        overflow: hidden;
    }
    .el-form-item__label{
        text-align:justify;
    }
    .el-form-item__label:after{
        display: inline-block; 
        content: '';
        padding-left: 100%; 
    } 
    .password-button{
        height: 40px;
        width: 100%;
        line-height: 40px;
        color: #fff;
        text-align: center;
        font-size: 16px;
        background-color: #5d2805;
        display: block;
        border-radius: 5px;
        // width: 57%;
    }
    .yzm{
        .el-form-item__content{
            text-align: left;
            .el-input{
                width: 57%;
            }
            .fsYzm{
                width: 42%;
                height: 40px;
                line-height: 40px;
                display: block;
                text-align: left;
                font-size: 12px;
                float: right;
                color: #5d2805;
                border-radius: 5px;
            }
        }
    }
}
</style>

